import { defineStore } from 'pinia';
import dayjs from 'dayjs';

export const useRentalStore = defineStore('rental', {
  state: () => ({
    pickupDate: dayjs().format('YYYY-MM-DD'),
    returnDate: dayjs().add(3, 'day').format('YYYY-MM-DD'),
    pickupCity: '',
    returnCity: '',
    carFilters: {
      brand: '',
      model: '',
      type: '',
      level: '',
      minPrice: '',
      maxPrice: '',
      powerType: '',
      seats: '',
      status: '可租'
    }
  }),

  getters: {
    rentalDays: (state) => {
      return dayjs(state.returnDate).diff(dayjs(state.pickupDate), 'day');
    }
  },

  actions: {
    setDates(pickup, returnDate) {
      this.pickupDate = pickup;
      this.returnDate = returnDate;
    },
    
    setCities(pickup, returnCity) {
      this.pickupCity = pickup;
      this.returnCity = returnCity || pickup;
    },
    
    setFilters(filters) {
      this.carFilters = { ...this.carFilters, ...filters };
    }
  }
}); 